/*
 *  Player.h
 *  GLRender
 *
 *  Created by Patrick zulian on 5/4/10.
 *  Copyright 2010 University  of Lugano. All rights reserved.
 *
 */

#ifndef PLAYER_H
#define PLAYER_H

#include "SpaceShip.h"
#include "Globals.h"
#include "WTarget.h"
#include "AbstractRenderer.h"
#include "WObject.h"
#include "Weapon.h"

class Bonus;

class Player {
private:
	WTarget *_objective;
	SpaceShip *_spaceShip;
	double theta;
	Weapon *weapon;
	bool _hasWin;
	double lastShoot, tookPowerUp ;
	bool _canShoot;
public:
	Player();
	
	Weapon * shoot(double time);
	void moveLeft();
	void moveRight();
	void moveUp();
	void moveDown();
	void accelerate();
	void brake();
	
	void rollCounterClockwise();
	void rollClockwise();
	
	Point3d getRadarTarget();
	double getTargetAltitude();
	double getAlpha();
	
	Point3d getTargetVector();
	
	virtual
	~Player(){}
	
	void step(double tau);
	
	void renderOn(AbstractRenderer *renderer);
	
	inline
	const Point3d position() const 
	{
		return _spaceShip->position();
	}
	
	inline const bool alive() const {return _spaceShip->alive();}
	
	inline void resurrect(){ _spaceShip->alive()=true; _hasWin=false;}
	
	inline
	const bool hasWin() const{
		return _hasWin;
	}
	
	inline
	void setObjective(WTarget *objective) 
	{
		_hasWin=false;
		_objective=objective;
		_spaceShip->resetAngles();
		_spaceShip->velocity()=globals::PLAYER_VELOCITY;
		_spaceShip->setLife(_spaceShip->getMaxLife());
	}
	
	inline
	Point3d& position()
	{
		return _spaceShip->position();
	}
	
	inline
	const Point3d velocity() const 
	{
		return _spaceShip->velocity();
	}
	
	inline
	Point3d& velocity() 
	{
		return _spaceShip->velocity();
	}
	
	inline
	Point3d& upperNormal()
	{
		return _spaceShip->upperNormal();
	}
	inline
	const Point3d upperNormal() const 
	{
		return _spaceShip->upperNormal();
	}
	
	void setWeapon (Weapon * weapon) {
		delete(this->weapon);
		this->weapon = weapon;
	}
	
	inline const double getLife()const {return _spaceShip->getLife();}
	inline const double getMaxLife()const {return _spaceShip->getMaxLife();}
	
	Weapon * getWeapon () { return this->weapon; }
	
	inline
	const double getLastShootTime () const { return this->lastShoot; }
	
	WObject * getObject();
	
	void checkShoot (double timeElapsed, double tau);
	
	bool canShoot ();
	
	void prepareForStep()
	{
		tookPowerUp = false;
	}
	inline
	void takenPowerUp()
	{
		tookPowerUp = true;
	}
	
	inline
	bool hasTakenPowerUp()
	{
		return tookPowerUp;
	}
	
	inline double getVerticalAngle(){
		return _spaceShip->verticalAngle();
	}
};


#endif
